<template>
  <div class="app-container">
    <!-- 筛选部分 -->
    <!-- <div class="search-container">
    </div> -->

    <!-- 公开展示的项目列表 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row=""
    >
      <el-table-column label="序号" min-width="30%" align="center">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="名称" min-width="50%" align="center">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="发布时间" min-width="50%" align="center">
        <template slot-scope="scope">
          {{ scope.row.reltime }}
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="50%" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleView(scope.row.projid)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pagenum" :limit.sync="listQuery.pagesize" @pagination="fetchData" />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getWorkList } from '@/api/work'

export default {
  name: 'WorkList',
  components: { Pagination },
  data() {
    return {
      listQuery: {
        pagenum: 0,
        pagesize: 10
      },
      list: null,
      total: 0
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      getWorkList(this.listQuery).then(res => {
        this.list = res.data.list
        this.total = res.data.total
      })
    },
    handleView(projid) {
      window.localStorage.setItem('detail_id', projid)
      window.localStorage.setItem('from', 'work')
      this.$router.push({ name: 'ProjectDetail', params: { id: projid }})
    }
  }
}
</script>
